﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ActionDisposable.cs" company="">
//   
// </copyright>
// <summary>
//   Allows action to be executed when it is disposed
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace Skymate.Utilities
{
    using System;

    /// <summary>
    ///     Allows action to be executed when it is disposed
    /// </summary>
    public struct ActionDisposable : IDisposable
    {
        /// <summary>
        ///     The _action.
        /// </summary>
        private readonly Action _action;

        /// <summary>
        ///     The empty.
        /// </summary>
        public static readonly ActionDisposable Empty = new ActionDisposable(() => { });

        /// <summary>
        /// Initializes a new instance of the <see cref="ActionDisposable"/> struct.
        /// </summary>
        /// <param name="action">
        /// The action.
        /// </param>
        public ActionDisposable(Action action)
        {
            this._action = action;
        }

        /// <summary>
        ///     The dispose.
        /// </summary>
        public void Dispose()
        {
            this._action();
        }
    }
}